using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using CCWin.SkinControl;
using System.Windows.Forms;
using Model;

namespace Scada
{
    public partial class ComboBoxEx : SkinComboBox
    {
        #region 属性

        /// <summary>
        /// 选中值
        /// </summary>
        public new object SelectedValue
        {
            get
            {
                if (base.SelectedValue == null)
                {
                    return string.Empty;
                }

                return base.SelectedValue;
            }

            set
            {
                object o = value;
                if (o == null)
                {
                    base.SelectedValue = string.Empty;
                }
                else
                {
                    base.SelectedValue = o + "";
                }
            }
        }

        /// <summary>
        /// 字段列表
        /// </summary>
        [Browsable(false)]
        public List<Cfg_Field> FieldList { get; set; } 

        #endregion 属性

        public ComboBoxEx()
        {
            InitializeComponent();
        }

        public ComboBoxEx(IContainer container)
        {
            container.Add(this);
            InitializeComponent();
        }

        /// <summary>
        /// 数据绑定
        /// </summary>
        public void Bind()
        {
            this.ValueMember = "value";
            this.DisplayMember = "name";
            this.FieldList.Insert(0,new Cfg_Field() { name="",value=""});
            this.DataSource = this.FieldList;
            this.DropDownStyle = ComboBoxStyle.DropDownList;
        }
    }
}
